/*
* @Author: steven.wang
* @Date:   2019-03-23 03:36:22
* @Last Modified by:   steven.wang
* @Last Modified time: 2019-05-13 14:45:01
*/
const db = require('../db');
/**
 * 查询职位
 * @author steven.wang
 * @DateTime 2019-03-23T03:38:45+0800
 */
module.exports.list = values => {
	const dbSql = db.generateSql({
		wants: '*',
		action: 'search',
		table: 'job',
		conditions: {
			source: [values.source === '' && ''],
			city: [values.city || ''],
			company_name: [values.company_name || ''],
			education: [values.education || ''],
			experience: [values.experience || ''],
			type: [values.type || ''],
			salary: [values.salary || '']
		},
		likes: {
			name: values.name
		},
		sorts: values.sorts,
		pages: {
			page: parseInt(values.page) || 1,
			pageSize: parseInt(values.pageSize) || 10
		}
	});
	return db.query(dbSql.sql, dbSql.sqlData);
}
/**
 * 获取职位总数
 * @author steven.wang
 * @DateTime 2019-03-23T03:38:45+0800
 */
module.exports.count = values => {
	const dbSql = db.generateSql({
		wants: 'count(*)',
		action: 'search',
		table: 'job',
		conditions: {
			source: [values.source === '' && ''],
			city: [values.city || ''],
			company_name: [values.company_name || ''],
			education: [values.education || ''],
			experience: [values.experience || ''],
			type: [values.type || ''],
			salary: [values.salary || '']
		},
		likes: {
			name: values.name
		}
	})
	return db.query(dbSql.sql, dbSql.sqlData);
}
/**
 * 添加职位
 * @author steven.wang
 * @DateTime 2019-03-23T03:38:45+0800
 */
module.exports.add = values => {
	const dbSql = db.generateSql({
		action: 'add',
		table: 'job',
		conditions: [values]
	});
	return db.query(dbSql.sql, dbSql.sqlData);
}

/**
 * 删除职位
 * @author steven.wang
 */
module.exports.delete = values => {
	const dbSql = db.generateSql({
		action: 'delete',
		table: 'job',
		conditions: {
			id: values.ids
		}
	});
	return db.query(dbSql.sql, dbSql.sqlData);
}

/**
 * 更新职位
 * @author steven.wang
 * @DateTime 2019-03-23T03:38:45+0800
 */
module.exports.update = values => {
	let id = values.id;
	delete values.id;
	const dbSql = db.generateSql({
		action: 'update',
		table: 'job',
		wants: values,
		conditions: {
			id: id
		}
	});
	return db.query(dbSql.sql, dbSql.sqlData);
}